//去重
const arr = [1, 1, 2, 2]
const arr2 = [...new Set(arr)]
console.log(arr2)

//判断元素是否在集合中
const set = new Set(arr)
const has = set.has(1)
console.log(has)

//求交集
const set2 = new Set([2, 3])
const set3 = new Set([...set].filter((item) => set2.has(item)))
console.log(set3)

//两个数组的交集  时间复杂度O(n²)  空间复杂度O(m) ，为 num1去重后的长度
var intersection = function(num1, num2) {
  return [...new Set(num1)].filter(n => num2.includes(n))
}
